package com.pda.xinma.presenter;

import com.pda.xinma.bean.HandingOutStaticsBean;
import com.pda.xinma.bean.HnadingInDetailListBean;
import com.pda.xinma.contract.HandingOutStaticsContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class HandingOutStaticsPresenter extends BasePresenter<HandingOutStaticsContract .View> implements HandingOutStaticsContract.Presenter{

    @Override
    public void deliveryStatistics(String deliveryNo) {
        NetUtils.geApi().deliveryStatistics(deliveryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HandingOutStaticsBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HandingOutStaticsBean> handingOutStaticsBeanBaseAppEntity) throws Exception {
                        getView().setList(handingOutStaticsBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void deliveryCloseInfo(String deliveryNo) {
        NetUtils.geApi().deliveryCloseInfo(deliveryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HnadingInDetailListBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HnadingInDetailListBean> hnadingInDetailListBeanBaseAppEntity) throws Exception {
                        getView().setCloseMsg(hnadingInDetailListBeanBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void deliveryClose(String deliveryNo) {
        NetUtils.geApi().deliveryClose(deliveryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HnadingInDetailListBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HnadingInDetailListBean> hnadingInDetailListBeanBaseAppEntity) throws Exception {
                        getView().finishActivity();
                        getView().showMessage(hnadingInDetailListBeanBaseAppEntity.getMsg());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
